<?php
	class comment{
		public $id;
		public $tendangnhap;
		public $tivi_id;
		public $parent_id;
		public $noidung;
		public $thoigian;
		public $trangthai;
		public function getCommentByWhere($where,$order){
			
			$db = new db();
			$db->getInstance();
			$sql = "select * from tblbinhluan";
			if($where != '') $sql .= ' where ' . $where;
			if($order != '') $sql .= ' order by ' . $order; //echo $sql; die;
			$rs = mysql_query($sql);
			if(mysql_num_rows($rs)>0){
				while($rc = mysql_fetch_object($rs)){
					$lstHangSanXuat[] = $rc;	
				}
				return $lstHangSanXuat;
			}
			else return null;
		}
		
		public function getCommentByParentId($parent_id,$where){
			$db = new db();
			$db->getInstance();
			
			$sql = "Select * from tblbinhluan where  parent_id = " . $parent_id ;
			if($where != '') $sql .= ' and ' . $where; 
			$sql .= ' order by thoigian desc';
			$rs = mysql_query($sql);
			
			if(mysql_num_rows($rs)>0){
				//echo mysql_num_rows($rs);
				while($rc = mysql_fetch_object($rs)){
					$lstHangSanXuat[] = $rc;	
				}
				return $lstHangSanXuat;
			}
			else return null;
		}
		
		public function getCommentById($id){
			$db = new db();
			$db->getInstance();
			$sql = "Select * from tblbinhluan where id = " . $id; //echo $sql; 
			$rs = mysql_query($sql);
			$rc = mysql_fetch_object($rs);
			return $rc;
		}
		
		public function getCommentWherePaging($where, $order, $pos){
			
			$db = new db();
			$db->getInstance();
			$sql = "select * from tblbinhluan ";
			if($where != '') $sql .= ' where ' . $where; 
			if($order != '') $sql .= ' order by ' . $order;
			$sql .= ' limit '.$pos.','.__PAGE_SIZE; //echo $sql;die;
			$rs = mysql_query($sql);
			if(mysql_num_rows($rs) > 0){
				while($rc = mysql_fetch_object($rs)){
					$lstTivi[] = $rc;	
				}
				return $lstTivi;
			}
			else
				return null;
		}
		
		public function insert($comment){
			$db = new db();
			$db->getInstance();
			$sql = "Insert tblbinhluan(tendangnhap,tivi_id,parent_id,noidung,thoigian,trangthai) values('".$comment->tendangnhap."',".$comment->tivi_id.",".$comment->parent_id.",'".$comment->noidung."','".$comment->thoigian."',".$comment->trangthai.")"; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
		
		public function update($comment){
			$db = new db();
			$db->getInstance();
			$sql = "Update tblbinhluan set tendangnhap='".$comment->tendangnhap."',tivi_id=".$comment->tivi_id.",parent_id=".$comment->parent_id.",noidung='".$comment->noidung."',thoigian='".$comment->thoigian."',trangthai=".$comment->trangthai." where id =".$comment->id; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
		
		public function delete($id){
			$db = new db();
			$db->getInstance();
			$sql = "delete from tblbinhluan where id=".$id; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
	}
?>